<template>
    <div>
        <el-table :data="invalidList" border style="width: 100%">
            <el-table-column align="center" fixed prop="deb_name" label="应用名称" width="150"></el-table-column>
            <el-table-column align="center" prop="package_name" label="应用包名" width="120"></el-table-column>
            <el-table-column align="center" prop="version" label="应用版本" width="120"></el-table-column>
            <el-table-column align="center" prop="size" label="应用大小" width="120"></el-table-column>
            <el-table-column align="center" prop="website" label="网站" width="120"></el-table-column>
            <el-table-column align="center" prop="uploader" label="上传者" width="120"></el-table-column>
            <el-table-column align="center" label="应用分类" prop="category_id" width="120">
                <template slot-scope="scope">
                    <span>{{ display(scope.row) }}</span>
                </template>
            </el-table-column>
            <el-table-column align="center" fixed="right" label="操作">
                <template slot-scope="scope">
                    <el-button
                        @click="handleDownloadClick(scope.row)"
                        type="primary"
                        size="small"
                    >下载deb</el-button>
                    <el-button
                        @click="handlePassClick(scope.row)"
                        type="primary"
                        size="small"
                        :disabled="scope.row.validated"
                    >通过审核</el-button>
                </template>
            </el-table-column>
        </el-table>

        <form id="debDownloadForm" style="display:none;"></form>
    </div>
</template>

<script>
import {
    getInvalidList,
    passValidation,
    downloadDeb,
} from "../util/myRequests";

export default {
    name: "validate",
    components: {},
    data() {
        return {
            invalidList: [],
        };
    },
    computed: {
        categoryList() {
            return this.$store.state.categoryList;
        },
    },
    mounted() {
        getInvalidList()
            .then((res) => (this.invalidList = res))
            .catch((error) => console.log(error));
    },
    methods: {
        handleDownloadClick(item) {},
        handlePassClick(item) {
            passValidation(item.deb_id)
                .then((res) => {
                    item.validated = true;
                })
                .catch((error) => console.log(error));
        },
        download(item) {
            var form = document.getElementById("debDownloadForm");
            downloadDeb(item.deb_id, form);
        },
        display(item) {
            return this.categoryList.find((el) => el.id == item.category_id)
                .display;
        },
    },
};
</script>

<style>
</style>